<template>
  <div class="main flex-v">
    <div class="ioutWrap">
      <div class="balanceTop">
        <div style="position: relative;z-index: 3;">
          <!-- <go-back aa="../volunteer/indexs"></go-back> -->
          <headerBack></headerBack>
        </div>
        <div class="topHeadTitle">
          <span class="banTitle">您的专属方案已生成</span>
          <div class="watchNotes" @click="watchNotes">查看说明</div>
        </div>
      </div>
      <div class="programmeWrap">
        <scroller ref="scrollerBottom" style="top: 1.7rem;">
          <div class="programmeBox">
            <div class="new-case-box">
              <case-item @btnClick="getBalanceRecord" :isNew="true" :caseList="newCase"></case-item>
            </div>
            <div class="old-case-box" v-show="caseList.length>0">
              <h2 class="banTitle" >历史生成方案</h2>
              <case-item @btnClick="getBalanceRecord" :caseList="caseList" @delete="deltets"></case-item>
            </div>
            <div style="width: 7.5rem;height: 5.5rem;"></div>
          </div>
        </scroller>
        <div class="create-btn">
          <span @click="commonJs.gopush('../sxAssess/home')">创建新方案</span>
        </div>
      </div>
    </div>
      <comfirBox :showComfirm="showComfirm" confirBtnTxt="确定" @onCancel="showComfirm=false" @onConfirm="removeBalance">
        <div>
          <h2 style='text-align:center;color:#80D566'>提示</h2><p style='text-align:center;display:block;margin-top:0.2rem'>确定删除这个方案吗?</p>
        </div>
      </comfirBox> 
  </div>
</template>

<script>
import headerBack from "~/components/headerBack";
import caseItem from "./components/caseItem";
import { getBalanceHistory, getBalanceRecord, removeBalance } from "~/api/volunteer";
import comfirBox from '~/components/comfirBox'
import ls from "store2";
export default {
  head: {},
  components: {
    headerBack,
    caseItem,
    comfirBox
  },
  data() {
    return {
      showComfirm:false,
      caseList: [],
      newCase: []
    };
  },
  methods: {
    // deltetsNew(id,index){
    //   this.id = id
    //   this.$indexs =index 
    //   this.showComfirm=true
    //   this.deletetxt = 'newPlan'
    // },
    deltets(id,index){   
      this.id = id
      this.$indexs =index 
      this.showComfirm=true
    },
    removeBalance(){
      let _this = this
      let obj={
        id:this.id
      }
      removeBalance(obj).then(res=>{
        if(res.code=='0'){
          if(this.deletetxt =='newPlan'){
            this.newCase=[]
          }else{
            this.caseList = this.caseList.filter(function(item, $index) {
              return $index != _this.$indexs;
            });
          }
           
        }else{
          this.$vux.toast.text(res.data.message)
        }
        this.showComfirm=false
      })
    },
    getBalanceRecord(id, tys) {
      this.$loading('open');
      let that = this;
      getBalanceRecord(id)
        .then(res => {
          if (res.code == "0") {
            if (res.data) {
              ls.set("caseData1", res.data.balance);
              ls.set("caseData2", res.data.academy);
              ls.set("caseData3", res.data.major);
              setTimeout(() => {
                ls.set("preUrl", "../volunteer/programrecord");
                that.$store.commit("changeUrl", "../volunteer/programrecord");
                that.commonJs.gopush("../volunteer/balance", tys);
              }, 50);
            }
          }
          this.$hideLoading();
        })
        .catch(error => {
          this.$hideLoading();
        });
    },
    hasBalanceHistory() {
      this.$loading('open');
      getBalanceHistory(ls.get("userType"))
        .then(res => {
          if (res.code == "0") {
            if(res.data.length>0){
                this.newCase.push(res.data[0]);
                this.caseList = res.data.filter(function(item, index) {
                return index > 0;
                });
            }
           
          }
          this.$hideLoading();
        })
        .catch(error => {
          this.$hideLoading();
        });
    },
    watchNotes() {
      this.commonJs.gopush("notes", 2);  
    }
  },

  mounted: function() {
    this.$visit(this.$route.path)
    this.hasBalanceHistory();
  }
};
</script>

<style scoped lang="less">
.ioutWrap {
  width: 100%;
  min-height: 100vh;
  background: #fff;
  position: relative;

  .balanceTop {
    // z-index: 2;
    width: 100%;
    height: 1.7rem;

    .topBg {
      position: absolute;
      right: 0;
      top: 0;
      width: 7.5rem;
      height: auto;
    }

    .topHeadTitle {
      display: flex;
      justify-content: space-between;
      align-items: center;
      // margin-top: 0.4rem;
      margin-left: 0.3rem;
      margin-right: 0.31rem;

      .watchNotes {
        color: #222;
        font-size: 0.3rem;
        line-height: 0.44rem;
      }
    }
  }
  .banTitle {
    display: block;
    height: 0.62rem;
    font-size: 0.4rem;
    font-weight: bold;
    color: rgba(34, 34, 34, 1);
    display: block;
  }
}

.programmeWrap {
  width: 7.5rem;
  min-height: 100vh;
  height: auto;

  .pycsBox {
    display: block;
    height: 0.8rem;
    line-height: 0.8rem;
    overflow: hidden;
    background: #fff1b8;
    padding: 0 0.3rem;

    .bb1 {
      font-size: 0.26rem;
      font-weight: bold;
    }

    .ii1 {

      display: inline-block;
      color: @mainColor;
      font-size: 0.3rem;
      height: 0.6rem;
      width: 1rem;
      text-align: center;
      line-height: 0.6rem;

      margin-top: 0.1rem;

      font-family: "PingFangSC-Semibold";
      font-weight: 600;
    }
  }

  .programmeBox {
    width: 100%;
    min-height: 15rem;
    height: auto;
    // padding: 0.3rem 0;
    box-sizing: border-box;
    position: relative;
    .new-case-box {
      width: 100%;
      height: auto;
      padding: 0 0.3rem 0.4rem 0.3rem;
      // box-sizing: border-box;
      // border-bottom: 0.24rem solid rgba(247, 247, 250, 1);
    }
    .old-case-box {
      width: 100%;
      height: auto;
      border-top: 0.24rem solid rgba(247, 247, 250, 1);
      padding: 0.5rem 0.3rem 0.3rem 0.3rem;
    }

    .textTitle {
      font-size: 0.5rem;
      font-weight: bold;
      color: rgba(34, 34, 34, 1);
      line-height: 0.8rem;
      display: block;
      margin-bottom: 0.6rem;
    }

    .proSmBox {
      margin-bottom: 0.2rem;
      width: 100%;
      height: 2.4rem;

      box-shadow: 0px 0px 0.2rem 0px rgba(204, 204, 204, 0.3);
      border-radius: 0.1rem;

      .left {
        padding-left: 0.3rem;
        box-sizing: border-box;

        .lefttxt1 {
          font-size: 0.4rem;

          font-weight: bold;

          line-height: 0.6rem;
          display: block;
        }

        .l1 {
          color: rgba(148, 210, 103, 1);
        }

        .l2 {
          color: rgba(254, 192, 62, 1);
        }

        .l3 {
          color: rgba(90, 178, 241, 1);
        }

        .lefttxt2 {
          display: block;
          height: auto;
          font-size: 0.24rem;

          font-weight: 500;
          color: rgba(153, 153, 153, 1);
          line-height: 0.4rem;
        }
      }

      .right {
        width: 2.43rem;
        height: 2.4rem;

        img {
          display: block;
          width: 100%;
          height: 2.4rem;
        }
      }
    }
  }
}

.create-btn {
  position: fixed;
  width: 100%;
  left: 0;
  bottom: 0;
  height: auto;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px -0.04rem 0.1rem 0px rgba(204, 204, 204, 0.2);
  span {
    display: block;
    margin: 0.2rem auto;
    width: 6rem;
    height: 0.88rem;
    background: @assistColor;
    border-radius: 0.44rem;
    text-align: center;
    line-height: 0.88rem;
    font-size: 0.3rem;
    font-family: PingFangSC;
    font-weight: 600;
    color: rgba(255, 255, 255, 1);
  }
}
</style>
